package com.example.springbootredis.web;


import com.alibaba.fastjson.JSON;
import com.example.springbootredis.domian.User;
import com.example.springbootredis.service.RedisService;
import com.example.springbootredis.util.RedisUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author dongxing
 **/
@RestController
@RequestMapping("1")
@AllArgsConstructor(onConstructor_ = {@Autowired})
@Slf4j
public class UserController {

    private RedisUtil redisUtil;
    private RedisService redisService;

//    private RedisDao redisDao;

    @GetMapping("/w")
    public String show() {
        User user = User.builder().build();
        user.setName("中午")
                .setCity("上海");

        redisService.set("1111", user);
        redisService.set("222", user);
        redisService.set("77777777", "2222");
        Object o = redisService.get("222");

        System.out.println("---------" + o);

        System.out.println("序列化" + JSON.toJSONString(o));
        System.out.println("序列化" + JSON.toJSONString(o));

        return "Success";
    }
}
